/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 *
 * @author MarcoPc
 */
public class Show {

    private int[][] tickets;
    private String movie;
    private String time;
    private ArrayList<ActionListener> listeners;

    public Show(int rows, int seats, String movie, String time) {
        tickets = new int[rows][seats];
        this.movie = movie;
        this.time = time;
        listeners = new ArrayList<>();

        for (int x = 0; x < tickets.length; x++) {
            for (int y = 0; y < tickets[x].length; y++) {
                tickets[x][y] = 0;
            }
        }
    }

    public void bookTicket(int row, int seat, int customer) throws Exception {
        if (customer > 9999999 && customer < 100000000) {
            if (tickets[row][seat] == 0) {
                tickets[row][seat] = customer;
            } else if (tickets[row][seat] > 0) {
                throw new Exception("Pladsen er optaget.");
            }
        }else{
            throw new Exception("Tjek om TLF er Skrivet rigtigt");
        }
        notifyListeners();
    }

    public int getRows() {
        int antalRows = 0;
        for (int i = 0; i < tickets.length; i++) {
            antalRows = tickets.length;
            for (int j = 0; j < tickets[i].length; j++) {
            }
        }
        return antalRows;
    }

    public int getSeats() {
        int antalSeats = 0;
        
        for (int i = 0; i < tickets.length; i++) {
            for (int j = 0; j < tickets[i].length; j++) {
                 antalSeats = (tickets[i].length);
            }
        }
        return antalSeats;
    }

    public String getShow(int customer) {
        String show = "\nFilm: " + "\t" + movie + "\n" + "Tid: " + "\t" + time + "\n\n\t     -----Læred-----";
        show = show + "\nRække:";

        for (int i = 0; i < tickets.length; i++) {
            int row = i + 1;
            show = show + "\n " + row + ": \t ";
            for (int j = 0; j < tickets[i].length; j++) {
                if (tickets[i][j] == 0) {
                    show = show + ". ";
                } else if (tickets[i][j] == customer) {
                    show = show + "# ";
                } else {
                    show = show + "X ";
                }
            }
        }
        show = show + "\n\nSæde Nr:\t\t   1 1 1 \n\t 1 2 3 4 5 6 7 8 9 0 1 2";
        return show;
    }
    
    public void addListener(ActionListener listener) {
        listeners.add(listener);

    }

    public void notifyListeners() {
        for (ActionListener actionListener : listeners) {
            actionListener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ""));
        }
    }
    
}
